package luigibros.window;

import java.awt.Image;
import java.awt.image.ImageObserver;
import java.util.Random;

public class Ghost extends Craft {
	protected int d;
	private boolean isX;
	private boolean forward;
	protected Random r;
	public int starCount;
	private Craft craft;
    public Ghost(Image i, ImageObserver obs, Craft c) {
    	super(i, obs);
    	r = new Random();
        x = (int) (150 * r.nextGaussian()) + 350;
        y = (int) (250 * r.nextGaussian()) + 450;
        d = 1;
        craft = c;
    }


    public void move(int sc) {
    	starCount = sc;
    	if(starCount == 0)
	    {
    		if(r.nextGaussian() < -.75)
	        	isX = !isX;
	        if(r.nextGaussian() < -.75)
	        	forward = !forward;
	        if(forward) {
	        	if(isX)
	 	        	x += d;
	 	        else
	 	        	y += d;
	        } else {
	        	 if(isX)
	 	        	x -= d;
	 	        else
	 	        	y -= d;
	        }
	    }
    	else if(starCount == 1)
    	{
    		if(this.getX() > craft.getX())
            	x += -1;
            else if(this.getX() < craft.getX())
            	x += 1;
            if(this.getY() < craft.getY())
            	y += 1;
            else if(this.getY() > craft.getY())
            	y += -1;
    	}
    	else if(starCount == 2)
    	{
    		if(this.getX() > craft.getX())
            	x += -2;
            else if(this.getX() < craft.getX())
            	x += 2;
            if(this.getY() < craft.getY())
            	y += 2;
            else if(this.getY() > craft.getY())
            	y += -2;
    	}
    }
    
    /*public boolean isX()
    {
    	return isX;
    }
   public boolean forward()
   {
	   return forward;
   }
   public Random random()
   {
	   return r;
   }
   public int returnD()
   {
	   return d;
   }*/
}

